

package cn.shengchao.controler;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.shengchao.cap.acl.adapters.repositories.ProductThirdCapOrderGradeRepository;
import cn.shengchao.examstar.product.ohs.local.appservice.ProductAppService;
import cn.shengchao.examstar.product.ohs.local.message.ProductDto;
import cn.shengchao.util.helper.LoginHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.continew.starter.web.model.R;

@Tag(name = "高考志愿服务购买")
@Slf4j
@RestController
@CrossOrigin("${project.cross-origin}")
@RequestMapping("/api/${project.version}/productThirdCap")
public class ProductThirdCapController {

    @Autowired
    private ProductAppService productAppService;
    @Autowired
    private ProductThirdCapOrderGradeRepository productThirdCapOrderGradeRepository;

    @SaIgnore
    @GetMapping("{productCapId}")
    @Operation(summary = "获取高考志愿服务产品", description = "获取高考志愿服务产品")
    public ProductDto getProductThirdCap(@PathVariable Long productCapId) {
        return productAppService.getProductById(String.valueOf(productCapId));
    }

    @GetMapping("ordered")
    @Operation(summary = "用户是否订阅生效", description = "用户是否订阅生效")
    public R<Boolean> ordered() {
        Long userId = LoginHelper.getUserId();
        if (userId!=null){
            return R.ok(productThirdCapOrderGradeRepository.isOrderValidForUser(userId));
        }else {
            return R.ok(false);}
    }

}
